/**
 * @author  along
 * 混入 返回上一页
 */
export const back = {
    data () {
        return {
            pathName: '',
            query: {}
        };
    },
    beforeRouteEnter(to, from, next) {
        next(vm => {
            vm.pathName = from.name;
            vm.query = from.query;
        });
    },
    destroyed(){
        window.removeEventListener('popstate', this.fnGoBack, false);
    },
    mounted () {
        this.fnRecord();
    },
    methods: {
        fnRecord () {
            if (window.history && window.history.pushState) {
                history.pushState(null, null, document.URL);
                window.addEventListener('popstate', this.fnGoBack, false);
            }
        },
        fnGoBack () {
            this.$router.replace({ name: this.pathName, query: this.query });
        }
    }
};
